﻿using System;
using System.Windows.Forms;
using LightLibrary;

public static class Factory {
	public static LibraryBase CreateLibrary(ExtensionTypeGroup libType, string libFullName) {
		switch(libType) {
			case ExtensionTypeGroup.Book:
				return new LibraryBooks(libFullName);
			case ExtensionTypeGroup.Unity:
				return new LibraryUnity(libFullName);
			default:
				MessageBox.Show("Unknown group type '" + libType + "'", @"Unknown library model", MessageBoxButtons.OK, MessageBoxIcon.Error);
				return null;
		}
	}

	public static LibraryBase CreateLibrary(LibraryModel libModel) {
		var lib = CreateLibrary(libModel.LibType, libModel.LibPath);
		lib.SetModel(libModel);
		libModel.Init();
		return lib;
	}

	public static IFormAssetEdit CreateFormAssetEdit(Asset asset) {
		if(asset.GetType() == typeof(AssetBooks)) {
			return new FormAssetBookEdit(asset) {
				StartPosition = FormStartPosition.CenterParent
			};
		} else {
			throw new Exception("Unknown asset type");
		}
	}

	public static DataGridViewRow CreateLibRow(DataGridView LibView, Asset asset) {
		if(asset.GetType() == typeof(AssetBooks)) {
			var assetBook = (AssetBooks)asset;
			return TableTools.CreateRowForBooks(LibView, false, asset.Name, assetBook.Title, assetBook.Authors, assetBook.Year, assetBook.Edition, asset.Extension, asset.SizeInBytes.ToString(), asset.PathRelativeToLib);
		} else {
			throw new Exception("Unknown asset type");
		}
	}
}